package com.bskj.common.utils;

import com.alibaba.fastjson.JSONObject;
import com.bskj.common.bean.vo.WechatPayVo;

public class H5PayUtils {
	private static final String orderUrl = "https://119.23.107.128/transaction/charge/test";

	public static JSONObject genPayOrder(WechatPayVo vo) throws Exception {
		JSONObject paramMap = new JSONObject();
//		String app_id = "wx66a812a9570f393a";
//		String merchant_code = "1003517014595076096";
//		String store_code = "666";
//		String operator = "";
//		String out_trade_no = StringUtils.getRandomWithTimestamp(32);
//		String channel = "WECHAT_OFFICE_ACCOUNT";
//		String client_ip = "127.0.0.1";
//		String amount = "10";
//		String ccy = "cny";
//		String subject = "停车费";
//		String body = "停车费";
//		String description = "停车费";
//		String notify_url = "";
//		String sign_type = "MD5";
//		String sign = "";
//
//		JSONObject dataJson = new JSONObject();
//		dataJson.put("sub_open_id", "ouUoA1jVIk0121cNfR21hw8zNCyI");
//		dataJson.put("sub_app_id", "wxa5337aa97b8fea09");
//		String extra = dataJson.toJSONString();

		paramMap.put("app_id", vo.getAppId());
		paramMap.put("merchant_code", vo.getMerchantCode());
		paramMap.put("store_code", vo.getStoreCode());
		paramMap.put("operator", vo.getOperator());
		
		paramMap.put("out_trade_no", vo.getOutTradeNo());
		paramMap.put("channel", vo.getChannel());
		paramMap.put("client_ip", vo.getClientIp());
		paramMap.put("amount", vo.getAmount());
		paramMap.put("ccy", vo.getCcy());
		paramMap.put("subject", vo.getSubject());
		paramMap.put("body", vo.getBody());
		paramMap.put("description", vo.getDescription());
		paramMap.put("notify_url", vo.getNotifyUrl());
		paramMap.put("sign_type", vo.getSignType());
		paramMap.put("sign", vo.getSign());
		if(vo.getChannel() == "WECHAT_OFFICE_ACCOUNT") {
			paramMap.put("extra", vo.getExtra());
		}

		System.out.println(paramMap);
		System.out.println(" orderUrl ======== " + orderUrl);
		String str = HttpClientUtils.doPost(orderUrl, paramMap.toString(), "UTF-8");
		return JSONObject.parseObject(str);
	}

	public static void main(String[] args) throws Exception {
		WechatPayVo vo = new WechatPayVo("wx66a812a9570f393a", "1003517014595076096", "666", "", "MD5", "", "麓谷信息港停车场");
		vo.setAmount("10");
		vo.setOutTradeNo(StringUtils.getRandomWithTimestamp(32));
		vo.setClientIp("127.0.0.1");
		vo.setSubOpenId("ouUoA1jVIk0121cNfR21hw8zNCyI");
		JSONObject resp = genPayOrder(vo);
		System.out.println(resp);
	}
}
